//
//  NSString+Json.m
//  YDCalculateTool
//
//  Created by YD_iOS on 16/6/13.
//  Copyright © 2016年 ios. All rights reserved.
//

#import "NSString+Json.h"

@implementation NSString (Json)
/** 处理json格式的字符串中的换行符、回车符 */
-(NSString *)deleteSpecialCode {
    
    NSArray *deleteStrArray = @[@"\r",@"\n",@"\t",@"~"];
    
    __block NSString *str = self;
    
    [deleteStrArray enumerateObjectsUsingBlock:^(NSString *deleteStr, NSUInteger idx, BOOL *stop) {
        
        str = [str stringByReplacingOccurrencesOfString:deleteStr withString:@""];
    }];
    
    return str;
}

/**
 *  将json字符串 转换为字典
 *
 *  @param jsonString <#jsonString description#>
 *
 *  @return <#return value description#>
 */
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    
    if (jsonString == nil)
    {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    
    if (err)
    {
        NSLog(@"json解析失败:%@", err);
        return nil;
    }
    
    return dic;
}

@end
